package com.dark;

import org.jsoup.Connection;
import org.jsoup.Jsoup;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by tengxue on 16-4-25.
 */
public class FaceBookLoginTest {

    private static final String LOGIN_URL="https://www.facebook.com/login.php?login_attempt=1&lwv=110";
    public static void main(String[] args) throws IOException {
        Map<String, String> map = new HashMap<String, String>();
        map.put("lsd", "AVrXAwTt");

        map.put("email","xt0000201101@163.com");
        map.put("pass", "xt1985317");
        map.put("persistent", "");
        map.put("default_persistent", "1");
        map.put("timezone", "-480");
        map.put("lgndim", "eyJ3IjoxNjAwLCJoIjo5MDAsImF3IjoxNTM1LCJhaCI6ODc2LCJjIjoyNH0=");
        map.put("lgnrnd", "233200_wltA");
        map.put("lgnjs", "1461565924");
        map.put("locale", "zh_CN");
        map.put("qsstamp", "W1tbMyw0Myw1MCw4NCw4Nyw5Miw5MywxMTQsMTIxLDEyMiwxMjQsMTU4LDE2NCwxNzMsMTgwLDE5MCwyMjQsMjM4LDI2NSwzMjgsMzQxLDM0NSwzNTMsMzc2LDM3OCwzOTEsNDEyLDQyNCw0NjcsNDg4LDQ5OSw1MjYsNTI5LDUzMSw1MzcsNTM4LDU2NCw1NzUsNTgxLDYwMyw2MTAsNjgxXV0sIkFabEFnRm1ndEZtQkt1WTcwSk9iYjNyMzRlYmUwYnRJSk5ZVDV6MHFjaENoLVJtQnNMeGJJVjFlVzdVcXdSZElRYmtPbzhDWWVDVmpDTFNHM2tGOURSdWJCUUJLQWRFOTNLMnVTenpjbkZ4SkRnaWZSQ2pnV2lIa1FmUGpKNVNfVzFOY2N0SG44aGV5MmUxb1Nhamp1NjFhcDdNeWZ6Y0xvQVM3YkxBb2RLVTlsWVRhRmNWc2E1Wm84ZFZtZTFZb2RRbHdHZnpDSXJOb2hXYjVPRi1YaUhUTGFiSkkwdkF0YmZHVEZIbF9BWDV4T1l2WnVaMFZBdE43ejRXX1pOYmNwb2ciXQ==");

        Map<String,String> cookies=new HashMap<String, String>();
        cookies.put("datr","mj0YV6SxTt5rOTKQNo-rTxRg");
        cookies.put("locale","zh_CN");
        cookies.put("sb","3z0YV8VGgw-GzQUtjwlWHZOO");
        cookies.put("fr","0o78o72SzzJcmq5Ps.AWXrqYEH-gB-6OmB3ezvyjVU9Ac.BXGD3g.88.AAA.0.AWU_ty-b");
        cookies.put("lu","gAi78Cam-mQTUBOW8ZVdZCew");
        cookies.put("reg_fb_ref","https%3A%2F%2Fwww.facebook.com%2F%3Fstype%3Dlo%26jlou%3DAfdCbXmwpouL_hWdZFJsNz_aCHs-3cNLMkBZhyymHTg-M-PcS9FGK8k8HL07ZHifngYCXyUJdjdMrVP_wFDUt01ozR7RILJ_e6JopyoBSd9XBA%26smuh%3D43344%26lh%3DAc_HIuKg-RVRNe2E");
        cookies.put("reg_fb_gate","https%3A%2F%2Fwww.facebook.com%2F%3Fstype%3Dlo%26jlou%3DAfdCbXmwpouL_hWdZFJsNz_aCHs-3cNLMkBZhyymHTg-M-PcS9FGK8k8HL07ZHifngYCXyUJdjdMrVP_wFDUt01ozR7RILJ_e6JopyoBSd9XBA%26smuh%3D43344%26lh%3DAc_HIuKg-RVRNe2E");
        cookies.put("wd","1535x384");


        Connection conn = Jsoup.connect(LOGIN_URL);
//        conn.header("(Request-Line)", "POST /cgi-bin/login?lang=zh_CN HTTP/1.1");
        conn.header("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
        conn.header("Accept-Encoding", "gzip, deflate");
        conn.header("Accept-Language", "zh-CN,zh;q=0.8");
        conn.header("Cache-Control", "no-cache");
        conn.header("Connection", "Keep-Alive");
        conn.header("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
        conn.header("host", "www.facebook.com");
        conn.header("Referer", "https://www.facebook.com/?stype=lo&jlou=AfdCbXmwpouL_hWdZFJsNz_aCHs-3cNLMkBZhyymHTg-M-PcS9FGK8k8HL07ZHifngYCXyUJdjdMrVP_wFDUt01ozR7RILJ_e6JopyoBSd9XBA&smuh=43344&lh=Ac_HIuKg-RVRNe2E");
        conn.header("User-Agent", "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.111 Safari/537.36");
        conn.cookies(cookies);

        Connection.Response response = conn.ignoreContentType(true).method(Connection.Method.POST).data(map).execute();
        String body=response.body();
        System.out.println("body is :" + body);

        Map<String,String> resCookies=response.cookies();

        System.out.println("resCookies is :" + resCookies);
    }
}
